package org.reliablesource.prism.ui.viewers;

/**
 *
 *  Copyright (c) 2006, Reliable Source, Inc. All Rights Reserved
 *
 *	Created on: Mar 11, 2006
 *	@author Dennis Park <a href="mailto:dennis.park@gmail.com">dennis.park@gmail.com</a>
 *
 */

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.reliablesource.prism.core.IPrismModel;
import org.reliablesource.prism.core.IPrismNode;
import org.reliablesource.prism.core.IPrismUnit;
import org.reliablesource.prism.core.plugin.PrismCorePlugin;

public class PrismElementTreeContentProvider implements ITreeContentProvider {
	
	public Object[] getElements(Object inputElement) {
		return ((IPrismModel) inputElement).getChildren();
	}

	public void dispose() {
	}

	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
	}

	public Object[] getChildren(Object parentElement) {
		if (parentElement instanceof IPrismNode)
			return ((IPrismNode) parentElement).getChildren();
		return PrismCorePlugin.NULL_OBJECT;
	}

	public Object getParent(Object element) {
		if (element instanceof IPrismUnit)
			return ((IPrismUnit) element).getParent();
		else if (element instanceof IPrismNode)
			return ((IPrismNode) element).getParent();
		return null;
	}

	public boolean hasChildren(Object element) {
		if (element instanceof IPrismModel)
			return true;
		else if (element instanceof IPrismNode
				&& ((IPrismNode) element).getChildListSize() > 0)
			return true;
		return false;
	}

}
